Skip to content

feat(ai): OpenAI-compatible provider for local and third-party models - #48

Merged
ChristopherDownie merged 1 commit into
mainfrom
feat/openai-compatible-provider
Oct 15, 2026
Merged

ChristopherDownie merged 1 commit into
mainfrom
feat/openai-compatible-provider

Conversation

@ChristopherDownie

Copy link
Copy Markdown
Contributor

Adds custom AI provider support, replacing #19 with a narrower design.

What's new

  • OpenAI-compatible provider in Settings → AI, with a server URL, model ID and optional API key. It works with Ollama, LM Studio, OpenRouter, vLLM and any server that implements Chat Completions. It powers recaps, trade critiques and Ask your journal.
  • Gateways for Anthropic/OpenAI via the SDKs' standard ANTHROPIC_BASE_URL / OPENAI_BASE_URL env vars. These already worked but were undocumented; they're now in the README and .env.example and pinned by a test.

Security

  • The compatible provider never receives ANTHROPIC_API_KEY or OPENAI_API_KEY. It uses @ai-sdk/openai-compatible, which reads no environment variables, and it has no env key of its own.
  • A saved compatible key is bound to its URL: saving a different URL removes the key unless a new one is sent in the same request. Changing the URL can't redirect a stored key.
  • URLs must be http(s), with no embedded credentials, query or fragment, and at most 2048 characters.
  • Hosted-provider base URLs can only be set by the operator through the environment, never through the settings API.

Scope

  • AI statement parsing on the Import page stays on Anthropic/OpenAI, since it needs PDF input and strict structured output. The server rejects provider: "compatible" there.
  • @ai-sdk/openai-compatible is pinned to 3.0.46, which shares @ai-sdk/provider / provider-utils with the installed @ai-sdk/openai. It adds no new transitive packages and is Apache-2.0.

Tests

  • Configured state: a compatible server needs a URL and model but no key.
  • Requests go to <url>/chat/completions with no Authorization header and no env key.
  • A saved key is sent only to its own URL; a new URL drops it; trailing slashes don't count as a change.
  • Malformed URLs are rejected before anything is written.
  • An unreachable server gives a clear notice that doesn't leak request details.
  • Anthropic/OpenAI requests follow the gateway env vars.
  • Import rejects the compatible provider.
  • UI test for the Settings form.

pnpm format:check, pnpm typecheck, pnpm test (614 tests), the license gate and pnpm build all pass locally.

Not included: the Markdown rendering of Ask Journal answers from #19. If wanted, it should reuse the existing <Markdown> component in a separate PR.

… models

Adds a third AI provider, "OpenAI-compatible", for Ollama, LM Studio,
OpenRouter, vLLM and other servers that speak the Chat Completions API.
It has its own server URL, model and optional encrypted key, and uses
@ai-sdk/openai-compatible, which never reads provider environment
variables, so ANTHROPIC_API_KEY / OPENAI_API_KEY are never sent to a
user-supplied URL. A saved key is bound to the URL it was saved with:
saving a different URL clears it unless a new key is sent.

Anthropic and OpenAI gateways keep working through the SDKs' standard
ANTHROPIC_BASE_URL / OPENAI_BASE_URL variables, now documented and
covered by a test. AI statement parsing stays on Anthropic and OpenAI,
which accept PDFs and strict structured output.

Replaces #19; thanks to @fiandev for the proposal.
@ChristopherDownie
ChristopherDownie merged commit f4784d6 into main Oct 15, 2026
1 of 2 checks passed
@ChristopherDownie
ChristopherDownie deleted the feat/openai-compatible-provider branch October 28, 2026 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant